package com.waves.task.strategy.task;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.waves.core.utils.StringUtils;
import com.waves.task.domain.dto.TaskPageDTO;
import com.waves.task.domain.enums.TaskTypeEnum;
import com.waves.task.domain.vo.TaskVO;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 热门贴策略类
 */
@Component
public class TaskHotStrategy extends AbstractTaskStrategy {
    @Override
    TaskTypeEnum getTaskTypeEnum() {
        return TaskTypeEnum.TASK_TYPE_HOT;
    }

    @Override
    public TaskPageDTO dealTaskPageDTO(TaskPageDTO dto) {
        return dto;
    }

    @Override
    public IPage<TaskVO> getTaskVOPage(TaskPageDTO dto) {
        AtomicInteger num = new AtomicInteger(1);
        return super.searchAndDealPage(dealTaskPageDTO(dto)).convert(data -> {
            if (StringUtils.isEmpty(data.getTitle())) {
                data.setTitle("热门交流贴-" + num.getAndIncrement());
            }
            return data;
        });
    }


}
